/**
 * TestManuscript.java is a JUnit Test Class is to test
 * the Manuscript class in the smart peer review program
 * for TCSS 360, Fall 2011.
 */
package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.junit.*;

import conference.Author;
import conference.Manuscript;
import conference.Review;
import conference.Reviewer;
import conference.Status;

/**
 * TestManuscript.java
 * @author Allison Graham
 * @version 1.0
 */
public class TestManuscript {
	private static int NUM_REVIEWS = 3; /**The number of reviews in the test object.*/
	private Manuscript myManuscript; /**the Manuscript test object.*/
    private String myTitle; /**The title for testing.*/
	private File myFile; /**The File object for testing.*/
	private Author myAuthor; /**The Author object for testing.*/
	private List<Review> myReviewList; /** The List of Reviews for this Manuscript.*/
	private Reviewer myReviewer; /**The Reviewer for this manuscript.*/
	
	/**initializes all test fields.*/
	@Before
	public void setUp() {
		myTitle = "Birds, dogs and other things that make noise.";
		myFile = new File("testFile.txt");
		myAuthor = new Author();
		myAuthor.setFirstName("Allison");
		myAuthor.setLastName("Graham");
		myAuthor.setEmail("grahaaj@gmail.com");
		myReviewList = new ArrayList<Review>(NUM_REVIEWS);
		myReviewer = new Reviewer("Alli", "Graha", "Review of xXX");
		for(int i = 0; i < NUM_REVIEWS;i++){
			myReviewList.add(new Review(myTitle + i, new File("testReview" + i), 
					myReviewer));
		}
		myManuscript = new Manuscript(myAuthor, myFile, myTitle);
	}
	
	/* Tests Manuscript(Author,File,Title) constructor.*/
    @Test
    public void testConstrutorAuthorFileTitle() {
    	assertSame("myManuscript.getAuthor() should equal theAuthor", myManuscript.getAuthor(), myAuthor);
    	assertSame("myFile should equal myManuscript.getFile().", myFile, myManuscript.getFile());
    	assertTrue("myTitle should equal myManuscript.getTitle().", myTitle.equals(myManuscript.getTitle()));
    	assertTrue("myManuscript.getStatus() should equal Status.UNDECIDED.", myManuscript.getStatus() == Status.UNDECIDED);
    	assertTrue("myManuscript.getReviews().size() should equal 0", myManuscript.getReviews().size() == 0);
    }
    
    /*Tests Manuscript(Manuscript,Status) constructor.
     * Constructor that creates a copy with the new status.
     * -precondition: none
     * -postcondition: myTitle == theManuscript.getTitle();
     * -postcondition: myFile == theManuscript.getFile();
     * -postcondition: super.getCreator() == theManuscript.getAuthor();
     * -postcondition: myStatus == theStatus;
     * -postcondition: myReviewLisst == myManuscript.getReviews();
     * @param theManuscript The manuscript to copy.
     * @param theStatus The status of the new copy.
     */
    @Test
    public void testConstructorManuscriptStatus() {
    	//Other conditions tested in previous tests.
    	Manuscript newManuscript = new Manuscript(myManuscript, Status.ACCEPTED);
    	assertTrue("newManuscript.getStatus() should equal Status.ACCEPTED", newManuscript.getStatus() == Status.ACCEPTED);
    	assertFalse("myManuscript.getStatus() should not equal newManuscript.getStatus()",
    			myManuscript.getStatus() == newManuscript.getStatus());
    }
	
	/*Test Manuscript(Manuscript, Review[]) constructor.*/
	@Test
	public void testConstructorManuscriptReviewList() {
		//Other conditions tested in previous tests.
		List<Review> newReviewList = new ArrayList<Review>(myReviewList);
		newReviewList.add(new Review("New Review", new File("ReviewTest"), new Reviewer("Allis", "Grah", "Review of XX")));
		Manuscript newManuscript = new Manuscript(myManuscript, newReviewList);
		assertNotSame("myReviewList and newReviewList should not be equal.", myReviewList, newReviewList);
		assertTrue("myReviewList.size() + 1 should be the same size as newManuscript.getReviews().size().", 
				myReviewList.size() + 1 == newManuscript.getReviews().size());	
	}
	
	/*Test getNumberOfReviews*/
	@Test
	public void testGetNumberOfReviews() {
		myManuscript = new Manuscript(myManuscript, myReviewList);
		int count = 0;
		for(Review r : myManuscript.getReviews()) {
			count++;
		}
		assertEquals("myManuscript.getNumberOfReviews() should equal count.", myManuscript.getNumberOfReviews(), count);
	}
	
	/*Test getNumberOfCompletedReviews()*/
	@Test
	public void testGetNumberOfCompletedReviews() {
		myManuscript = new Manuscript(myManuscript, myReviewList);
		int count = 0;
		for(Review r : myReviewList) {
			if (r.isComplete()) {
				count ++;
			}
		}
		assertTrue("should equal 3", myManuscript.getReviews().size() == 3);
		assertTrue("myManuscript.getNumberOfCompleteReviews() should equal count.", myManuscript.getNumberOfCompletedReviews() == 3);
		myReviewList.add(new Review(myReviewer));
		count = 0;
		for(Review r : myManuscript.getReviews()) {
			if (r.isComplete()) {
				count ++;
			}
		}
		assertTrue("myManuscript.getNumberOfCompleteReviews() should equal count after adding a Reviewer only Review.", myManuscript.getNumberOfCompletedReviews() == 3);
	}
}